package com.wang.designpattern.responsibilitychain;

import com.wang.designpattern.responsibilitychain.domain.AttendanceClockDO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 旷工处理类
 */
public class AmAbsentAttendanceHandler extends AttendanceHandler {
    public AmAbsentAttendanceHandler(String name) {
        super(name);
    }

    @Override
    public void processRequest(Map<String, AttendanceClockDO> clockResultDataMap, AttendanceClockDO attendanceClockDO) {
        // 初始打卡状态为正常AT06
        attendanceClockDO.setExceptionType(AttendanceConstant.ExceptionType.NORMAL.getExceptionType());
        AttendanceClockDO clockResultData = new AttendanceClockDO();
        //1、“上午实际上班打卡时间”为空
        if (StringUtils.isEmpty(attendanceClockDO.getAmStartTime())) {
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.ABSENT.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+0.5f);
            clockResultData.setExceptionUnit("D");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.ABSENT.getExceptionType(), clockResultData);
            handler.processRequest(clockResultDataMap, attendanceClockDO);
            return;
        }
        //2、“上午实际下班打卡时间”为空
        if (StringUtils.isEmpty(attendanceClockDO.getAmEndTime())) {
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.ABSENT.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+0.5f);
            clockResultData.setExceptionUnit("D");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.ABSENT.getExceptionType(), clockResultData);
            handler.processRequest(clockResultDataMap, attendanceClockDO);
            return;
        }
        //3、“上午实际上班打卡时间” - “上午上班时间” > 30分钟
        if (DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getAmStartTime(),
                attendanceClockDO.getAmSetStartTime()) > 30) {
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.ABSENT.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+0.5f);
            clockResultData.setExceptionUnit("D");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.ABSENT.getExceptionType(), clockResultData);
            handler.processRequest(clockResultDataMap, attendanceClockDO);
            return;
        }
        //4、“上午下班时间” - “上午实际下班打卡时间” > 30分钟
        if (DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getAmSetEndTime(),
                attendanceClockDO.getAmEndTime()) > 30) {
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.ABSENT.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+0.5f);
            clockResultData.setExceptionUnit("D");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.ABSENT.getExceptionType(), clockResultData);
            handler.processRequest(clockResultDataMap, attendanceClockDO);
            return;
        }
        handler.processRequest(clockResultDataMap, attendanceClockDO);
    }
}
